package com.example.teaching_server.entity;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.*;
import org.hibernate.annotations.CreationTimestamp;
import java.time.LocalDateTime;

/**
 * 教师班级关联实体类
 *
 * @author Teaching Server
 * @since 1.0.0
 */
@Getter
@Setter
@ToString(exclude = {"teacher", "classEntity"})
@EqualsAndHashCode(of = "id")
@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "teacher_class", indexes = {
        @Index(name = "idx_teacher_class_teacher", columnList = "teacher_id"),
        @Index(name = "idx_teacher_class_class", columnList = "class_id")
})
public class TeacherClass {

    /**
     * 关联ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 教师信息
     */
    @NotNull(message = "教师不能为空")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "teacher_id", nullable = false)
    private UserEntity teacher;

    /**
     * 班级信息
     */
    @NotNull(message = "班级不能为空")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "class_id", nullable = false)
    private ClassEntity classEntity;

    /**
     * 获取教师姓名
     */
    public String getTeacherName() {
        return teacher != null ? teacher.getUsername() : "";
    }

    /**
     * 获取班级名称
     */
    public String getClassName() {
        return classEntity != null ? classEntity.getClassName() : "";
    }
}
